<template>
	<div class="page-wrap">
		<div class="page-inner">
			<div class="page-table-ctx-wrap">
				<!-- 控制器 -->
				<div class="actions-box">
					<div class="control-box">
						<div class="control-left">
							<div class="control-item">
								<!-- <el-button type="primary" @click="doAdd()">
									添加
								</el-button> -->
							</div>
						</div>
						<div class="control-right">
							<div class="action-item">
								<el-date-picker v-model="time_range" type="daterange" align="right" unlink-panels range-separator="至"
									start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
									:picker-options="pickerOptions">
								</el-date-picker>
							</div>

							<div class="action-item">
								<el-select clearable="" v-model="searchParams.fahuoStatus" placeholder="状态筛选"
									@change="select_cate_onchange">
									<el-option v-for="item in status_select_options" :key="item.value" :label="item.title"
										:value="item.value">
									</el-option>
								</el-select>
							</div>
							<div class="action-item">
								<el-input clearable="" v-model="searchParams.keyword" placeholder="请输入关键词">
									<!-- <el-button slot="append" size="small" icon="el-icon-search" @click="doSearch()">
									</el-button> -->
								</el-input>
							</div>
							<div class="action-item">
								<el-button type="primary" @click="doSearch()">
									筛选
								</el-button>
							</div >
						</div>
					</div>
				</div>
				<!-- 控制器 -->

				<!-- 渲染表格 -->
				<div class="table-view">


					<w_table ref="w_table" @emitTable="emitTable" />
				</div>
				<!-- 渲染表格 -->
				<div class="table-util">
					<div class="util-left">
						<!-- 批量选择 -->
					</div>
					<div class="util-right">
						<div class="pagi-item">
							<w_pagination v-if="tableData.length" :total="total" :pagination="pagination" @size-change="onSizeChange"
								@current-change="onCurrentChange" />
						</div>
					</div>
				</div>
			</div>
		</div>

		<ship_form_modal ref="ship_form_modal" @confirm="confirmShip" />
	</div>
</template>

<script>
	import dayjs from 'dayjs';
	import {
		SHOP_TYPE
	} from '@/config/env.js'
	import ship_form_modal from '@/components/order/ship/ship_form_modal.vue'



	import page_config from "@/constant/ship/ship-list.js";
	import page_mixin from "@/mixins/page_mixin.js";
	export default {
		name: "news-list",
		mixins: [page_mixin],
		components: {
			ship_form_modal
		},
		data() {
			return {
				page_config,

				map_fahuoStatus: {
					1: '待发货 ',
					2: '已导出 ',
					3: '已作废 ',
					4: '已发货',
				},

				searchParams: {
					page: 1,
					pageNum: 10,
					fahuoStatus: '',
					keyword: '',
					startTime: '',
					endTime: '',
				},
				status_select_options: [{
						title: '全部状态',
						value: '',
					},
					{
						title: '待发货',
						value: 1,
					},
					{
						title: '已导出',
						value: 2,
					},
					// {
					// 	title: '已作废',
					// 	value: 3,
					// },
					{
						title: '已发货',
						value: 4,
					},
				],

				//
				time_range: [],

				pickerOptions: {
					disabledDate(time) {
						return time.getTime() > Date.now();
					},
					shortcuts: [{
							text: "最近一周",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
								picker.$emit("pick", [start, end]);
							},
						},
						{
							text: "最近一个月",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
								picker.$emit("pick", [start, end]);
							},
						},
						{
							text: "最近三个月",
							onClick(picker) {
								const end = new Date();
								const start = new Date();
								start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
								picker.$emit("pick", [start, end]);
							},
						},
					],
				},
			};
		},
		computed: {

		},
		watch: {
			time_range(value) {
				console.log('time_range', value)
				if (value && value.length) {
					this.searchParams.startTime = this.time_range[0] || ''
					this.searchParams.endTime = this.time_range[1] || ''
				} else {
					this.searchParams.startTime = ''
					this.searchParams.endTime = ''
				}
			}
		},
		created() {

		},
		mounted() {

		},
		methods: {
			format_list_data(list) {
				list.forEach(v => {
					let shouhuoJson = v.shouhuoJson || {};
					let {
						address,
						area,
						city,
						country,
						firstName,
						lastName,
						name,
						phone,
						province,
					} = shouhuoJson

					if (SHOP_TYPE == 'foreign') { //海外商城
						// v.cus_name = [name, firstName, lastName], filter(v => v).join(' ')
					} else {}
					v.cus_name = [name, firstName, lastName].filter(v => v).join(' ')
					v.cus_full_addr = [country, province, city, area].filter(v => v).join(' ')
					v.cus_phone = phone;


					//成单天数
					v.cus_day_number_to_creat = dayjs().diff(dayjs(v.createdTime), 'day') + '天';

					// 发货状态
					// 状态 ：1-待发货 2-已导出 3-已作废 4-已发货
					v.cus_fahuoStatus = this.map_fahuoStatus[v.fahuoStatus]
				})
			},
			doRowDetail(row) {
				this.$router.push({
					path: 'ship-detail',
					query: {
						id: row.id
					}
				})
			},
			doRowOther(row, action_title) {
				if (action_title == '发货') {
					this.doShip(row)
				}
			},
			doShip(row) {
				this.$refs.ship_form_modal.init(row)
			},
			confirmShip() {
				this.setView()
			},




			//筛选相关
			select_cate_onchange() {
				this.initQuery()
			}
		},
	};
</script>

<style scoped lang="less">
	// /deep/ .el-table table {
	//   width: 100% !important;

	//   thead {
	//     th.el-table__cell {
	//       background: #f8f8f8;
	//       color: #000;
	//     }
	//   }
	// }


	.page-table-ctx-wrap {
		background: #fff;
		padding: 20px;
		border-radius: 6px;
	}

	// 新增
	.control-box {
		.flex-between();

		.control-left {
			.flex();

			.control-item {
				margin-right: 10px;
			}
		}

		.control-right {
			.flex();

			.action-item {
				margin-left: 10px;
			}
		}
	}

	.table-view {
		margin-top: 20px;
		margin-bottom: 20px;
	}


	// 表格工具栏
	.table-util {
		.flex-between();

		.util-left {
			.flex();
			min-width: 100px;

			.util-items {
				.flex();

				.item {
					margin-right: 10px;
				}
			}
		}

		.util-right {}
	}
</style>